// *********************************************************
//      Copyright (c) Kosta Gaitanis
//      All rights reserved
//
//      k.gaitanis@gmail.com
//
// *********************************************************

#include "Cylinder.h"
#include "Trajectory.h"

Trajectory::Trajectory(double radius, const QString &name) :
    Item(name)
{
    /* FIXME complete the code */
    // each segment is a cylinder    
    double spacing = 20.0;  // the radial distance in degrees between two segments
    double rspacing = spacing / 2.0 / 180.0 * M_PI;  // the spacing in radians
    double r = 0.0015;       // the radius of each segment (cylinder radius)
    double segmentLength = rspacing * radius; // arc length = radians * radius
    for (int i =0; i <= 360/spacing; i++){
        Item* tra = new Cylinder(r, segmentLength/3, "Trajectory");
        tra->setTransform(Matrix::rotationZ( i * spacing / 180 * M_PI) * Matrix::translation(0, radius/2 , 0));
        addChild(tra);
    }
    // set up a material that glows in the dark
    getMaterial()->setEmission(QColor(50,120,255));
    getMaterial()->setAmbient(QColor(50,120,255));
    getMaterial()->setDiffuse(QColor(50,120,255));
    getMaterial()->setSpecular(QColor(50,120,255));
    getMaterial()->setShininess(20.0);
    /* STOP here */
}
